Questions
24 of 25
1How do you define a TypeORM entity and register it in a NestJS feature module?
2How do you handle TypeORM migrations in a NestJS project?
3How do you run a transaction with Prisma in NestJS?
4How do you perform CRUD operations and add query methods to a Mongoose model in NestJS?
5How do you use Prisma with multiple databases in a single NestJS application?
6What is the difference between find(), findOne(), findOneOrFail(), and the Query Builder in TypeORM?
7What are the two main ways to run a database transaction in TypeORM with NestJS?
8How do you handle Prisma migrations in a CI/CD pipeline?
9How do you add schema middleware (hooks) and instance methods in NestJS Mongoose?
10How do you mock a repository in a NestJS unit test?
11How do you seed a database in a NestJS application?
12How do you implement a Unit of Work pattern to group database operations across repositories in NestJS?
13How do you implement optimistic locking with TypeORM to prevent lost updates in NestJS?
14How do you integrate Prisma into a NestJS application?
15How do you implement soft deletes in NestJS with TypeORM?
16How do you implement multi-tenancy with a shared database in NestJS TypeORM?
17How do you set up TypeORM in a NestJS application?
18How do you implement a custom TypeORM repository in NestJS?
19How do you propagate a TypeORM transaction across multiple services in NestJS?
20What are Prisma middleware and how do you use them for audit logging in NestJS?
21How do you set up Mongoose in a NestJS application and define a schema?
22How do you handle Mongoose transactions for multi-document atomic operations in NestJS?
23What is the repository pattern and why use it in NestJS?
24How do you handle database connection pooling and health checks in NestJS?
25How do you implement database read replicas in NestJS for read/write splitting with TypeORM?
24 / 25

How do you handle database connection pooling and health checks in NestJS?

Configure the pool size via the extra option in TypeOrmModule.forRoot(). Use @nestjs/terminus with TypeOrmHealthIndicator for health checks. The health endpoint pings the database and returns a structured status object that load balancers and orchestrators can poll.

Connection pool configuration and health check endpoint
Connection pool and health check guidelines:
  1. 1

    max pool size should not exceed the database server's max_connections setting divided by the number of app instances.

  2. 2

    connectionTimeoutMillis: 2000 makes requests fail fast when the pool is exhausted rather than queuing indefinitely.

  3. 3

    @nestjs/terminus provides health indicators for TypeORM, Prisma, Redis, HTTP, DNS, and custom checks.

  4. 4

    Health endpoints are probed by Kubernetes liveness and readiness probes — keep them fast and lightweight.

  5. 5

    Use TypeOrmHealthIndicator.pingCheck() for TypeORM; write a custom indicator for Prisma using prisma.$queryRaw.